use std::fmt::{Display, Formatter};
use crossterm::*;
use crate::STAT;

#[derive(Debug, Eq, PartialEq)]
pub struct Stats {
    pub WAP: Vec<usize>,
    pub AC: usize,
    pub WA: usize,
    pub UN: usize,
}

impl Display for Stats {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        for i in &self.WAP {
            writeln!(f, "Point {} WA", i)?;
        }
        writeln!(f, "AC: {}, WA: {}, UN: {}", self.AC, self.WA, self.UN)?;
        writeln!(f, "AC Rate: {}", self.AC / (self.AC + self.WA + self.UN))?;
        std::fmt::Result::Ok(())
    }
}

pub async fn on_change() {
    let cs = Crossterm::new().terminal();
    cs.clear(ClearType::All).unwrap();
    println!("{}", STAT.lock().await);
}